<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

//include_once './org/code/Code.class.php';

class LoginController extends Controller
{
    //显示登录页面
    public function getLogin()
    {

        return view('admin.users.login');

    }

    public function postLogin(Request $request)
    {
       
        $data=$request->all();
        $code=new \Code;
        $_code=$code->get();
        if(strtoupper($request->input('code'))!=$_code){
            return back()->with('error','验证码错误');
        }
        $user=DB::table('admin')->where('adm_name',$data['adm_name'])->first();
       if($user){

           //验证密码
           if(Hash::check($data['adm_pwd'],$user['adm_pwd'])){
                session(['admin'=>$user]);
               return redirect('admin/user/index');
           }
       }
        return back()->with('error','用户名或密码失败');

    }

    //验证码输入
    public function getCode()
    {
        $code=new \Code();
        $code->make();
    }
    
    //修改密码
    public function pass()
    {
        
    }
    
    //退出登录
    public function quit()
    {
        session(['admin'=>null]);
        return redirect('admin/login');
    }
}
